using UnityEngine;
using System.Collections;

public class PlayerShoot : MonoBehaviour 
{
    public GameObject bullet;
    public Texture Crosshairtex;
    public Transform target;
	public GameObject balas;

	// Use this for initialization
	void Start () 
    {
	    
	}
	
	// Update is called once per frame
	void Update () 
    {
		    if(Input.GetButtonDown("Fire1"))
            {
                RaycastHit hit;
                
				if (Physics.Raycast(target.position, target.forward, out hit)) 
                {
					Vector3 hitpoint = hit.point;
					transform.LookAt(hitpoint);							
			
				Debug.Log("asdfas " + bullet.name);
					GameObject bullet1 = (GameObject) Instantiate(bullet, transform.position, Quaternion.identity);
					balas.GetComponent<ControlBalas>().actualizarBalas();
 //                   bullet1.transform.forward = transform.forward;
				Debug.Log("playerbala !! " + bullet1.GetComponent<ImpactoBalaPlayer>().name);
                    bullet1.GetComponent<ImpactoBalaPlayer>().damage = this.gameObject.transform.parent.GetComponent<PlayerControl>().DAMAGE;
                    
					Debug.Log("player ATACK!! " + this.gameObject.transform.parent.GetComponent<PlayerControl>().DAMAGE);
					bullet1.rigidbody.AddForce(transform.forward * 1000);
			    }
		    }
    }

    void OnGUI()
    {
	    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, new Vector3(Screen.width / 1024.0f, Screen.height / 768.0f, 1.0f));
	    GUI.DrawTexture (new Rect(500,372,24,24), Crosshairtex);

    }
	
}
